package com.sise.cn.api.common.impl;

import com.sise.cn.api.common.po.OrderItem;
import com.sise.cn.api.common.service.OrderItemService;
import com.sise.cn.dao.base.BaseMapper;
import com.sise.cn.dao.base.TableSpace;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 龚秀峰
 * @version 1.0
 * @date 2020/6/14 12:00
 * 订单项默认接口
 */
@Slf4j
@Service
@ConditionalOnMissingBean(OrderItemService.class)
public class OrderItemServiceImpl implements OrderItemService {
    @Resource
    private BaseMapper baseMapper;

    @Override
    public OrderItem getOrderItemById(Long id) {
        final OrderItem orderItem = new OrderItem();
        orderItem.setId(id);
        return baseMapper.select(orderItem, OrderItem.class);
    }

    @Override
    public Long saveOrderItem(OrderItem orderItem) {
        return baseMapper.insertAndGetId(orderItem);
    }

    @Override
    public void updateOrderItem(OrderItem orderItem) {
        baseMapper.update(orderItem);
    }

    @Override
    public List<OrderItem> getOrderItemByCondition(TableSpace tableSpace) {
        return baseMapper.selectList(tableSpace, OrderItem.class);
    }

    @Override
    public void deleteOrderItemById(Long id) {
        final OrderItem orderItem = new OrderItem();
        orderItem.setId(id);
        baseMapper.delete(orderItem);
    }
}
